package com.qq.spirit.model;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.qq.spirit.GameState;
import com.qq.spirit.UserState;

public class UserData
{
	private int gid = 0;
	private Map<String, String> gameInfo = new HashMap<String, String>();
	private Map<String, String> configMap = new HashMap<String, String>();

	// 用户登录Session
	private UserState userState = UserState.LOGIN_GAME;

	private GameState gameState = GameState.RUN;

	private Map<String, String> cookieMap = new HashMap<String, String>();

	public UserData(int gid)
	{
		this.gid = gid;
	}

	public int getGid()
	{
		return gid;
	}

	public void putConfig(String k, String v)
	{
		this.configMap.put(k, v);
	}

	public String getCookie(String name)
	{
		return cookieMap.get(name);
	}

	public GameState getGameState()
	{
		return gameState;
	}

	public void setGameState(GameState gameState)
	{
		this.gameState = gameState;
	}

	public void removeCookie(String name)
	{
		cookieMap.remove(name);
	}

	public void putCookie(String name, String v)
	{
		cookieMap.put(name, v);
	}

	public Iterator<String> getCookieKey()
	{
		return cookieMap.keySet().iterator();
	}

	public UserState getUserState()
	{
		return userState;
	}

	public void setUserState(UserState userState)
	{
		this.userState = userState;
	}

	public String getGameInfo(String infoname)
	{
		return gameInfo.get(infoname);
	}

	public void setGameInfo(String infoname, String infovalue)
	{
		this.gameInfo.put(infoname, infovalue);
	}

	public void setAllGameInfo(Map<String, String> gameInfo)
	{
		//设置cookieMap
		this.cookieMap.put("JSESSIONID", gameInfo.get("sessionid"));
		this.gameInfo.putAll(gameInfo);
	}

	public void setAllConfigInfo(Map<String, String> configInfo)
	{
		this.configMap.putAll(configInfo);
	}


	public String getConfigValue(String configname, String def)
	{
		return configMap.get(configname);
	}

	public void setConfigMap(String configname, String configvalue)
	{
		this.configMap.put(configname, configvalue);
	}

	public Map<String, String> getCookieMap()
	{
		return cookieMap;
	}

	public void setCookieMap(Map<String, String> cookieMap)
	{
		this.cookieMap = cookieMap;
	}

}
